package com.midian.model.common;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

/**
 * 
 * @Title:树状结构父类模型  
 * @Desription:树状结构父类模型
 * @Company:MDKG
 * @ClassName:TreeModel.java
 * @Author:Mengfh
 * @CreateDate:2013-6-7 下午5:29:54  
 * @UpdateUser:Mengfh  
 * @Version:0.1
 */
@MappedSuperclass
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class TreeModel<T extends TreeModel<?>> extends OrderModel{
	private static final long serialVersionUID = -8590258482215350948L;
	/**名称 */
	private String name;
	/** 父节点编号 */
	@Column(nullable=false,updatable=false,name="FPARENTID")
	private String fatherCode;
	@Transient
	private List<T> children;
	@Transient
	private Attr attr;

	public String getName() {
	    if(this.name != null) {
	        this.name = this.name.trim();
	    }
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setFatherCode(String fatherCode) {
		this.fatherCode = fatherCode;
	}
	public String getFatherCode() {
		return fatherCode;
	}
	public List<T> getChildren() {
		if(this.children==null){
			children = new ArrayList<T>();
		}
		return children;
	}
	public void setChildren(List<T> children) {
		this.children = children;
	}
	
	public String getData(){
		return this.name;
	}
	
	public Attr getAttr() {
		this.attr = new Attr();
		attr.setId(this.getId());
		attr.setName(this.getName());
		return attr;
	}
}
